<?php

class Reservations_ReadAction extends SrsReservationsBaseAction
{
	public function getCredentials()
	{
		return 'reservations.read';
	}

	public function executeRead(AgaviRequestDataHolder $rd)
	{
		$reservation = Doctrine_Query::create()
		               ->from('Reservation r')
			             ->innerJoin('r.User')
			             ->innerJoin('r.Hall')
			             ->where('r.id = ?', $rd->getParameter('id'))
									 ->fetchOne();

		if (!$reservation instanceof Reservation)
		{
			return $this->forward404();
   	}

		$overlapping = array();

		if ($reservation->status === 'new')
		{
			$overlapping = Reservation::findOverlapping(
				$reservation->hallId,
				$reservation->fromTime,
				$reservation->toTime,
				$reservation->id
			);
   	}

		$this->setAttribute('overlapping', $overlapping);
		$this->setAttribute('reservation', $reservation);

  	return 'Success';
	}
}